package com.citusdata.elven.feeder;


public class Log4jHelper {
  private static final String CLASS_SEPARATOR  = ".";
  private static boolean applicationNameSet = false;

  public static synchronized void setApplicationName(Class applicationClass) {
    // This method implicitly sets the name of the log file, where application's
    // output will be redirected. It does this by substituting a system property
    // value; this value gets read and expanded by log4j when reading the log4j
    // properties file.
    if (!applicationNameSet) {
      String applicationName = applicationClass.getName();

      int lastIndex = applicationName.lastIndexOf(CLASS_SEPARATOR);
      String logFileName = applicationName.substring(lastIndex + 1);
      System.setProperty("application-name", logFileName);

      applicationNameSet = true;
    }
  }
}
